package org.liyufeng.weixin.main;

import org.liyufeng.project.menu.Button;
import org.liyufeng.project.menu.Menu;
import org.liyufeng.project.menu.ViewButton;
import org.liyufeng.project.pojo.Token;
import org.liyufeng.project.util.CommonUtil;
import org.liyufeng.project.util.MenuUtil;
import org.liyufeng.project.util.ParamesAPI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 个人工资单菜单管理器类
 * 
 * @author liyufeng
 * @date   20141110
 */
public class MenuManagerPayrollPersonal4 {
	private static Logger log = LoggerFactory.getLogger(MenuManagerPayrollPersonal4.class);

	/**
	 * 定义菜单结构
	 * 
	 * @return
	 */
	private static Menu getMenu() {
		
		ViewButton btn1 = new ViewButton();
		btn1.setName("个人工资");
		btn1.setType("view");
		btn1.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3f25bc80e9df8a85&redirect_uri=http%3A%2F%2F公网IP%2Ftouchfuture_test%2Foauth2Servlet&response_type=code&scope=snsapi_base&state=payrollPersonal#wechat_redirect");
		
		ViewButton btn2 = new ViewButton();
		btn2.setName("部门工资");
		btn2.setType("view");
		btn2.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3f25bc80e9df8a85&redirect_uri=http%3A%2F%2F公网IP%2Ftouchfuture_test%2Foauth2Servlet&response_type=code&scope=snsapi_base&state=payrollDepartment#wechat_redirect");

		Menu menu = new Menu();
		menu.setButton(new Button[] { btn1 , btn2});

		return menu;
	}

	public static void main(String[] args) {	
		//输出OAuth2接口下payrollPersonal.jsp的网址
		String oauthUrl="http://42.96.139.34/touchfuture_test/OAuth2Servlet";
		System.out.println(CommonUtil.urlEncodeUTF8(oauthUrl));
		
		// 调用接口获取凭证
		Token token = CommonUtil.getToken(ParamesAPI.corpId, ParamesAPI.corpsecret);

		if (null != token) {
			// 创建菜单
			boolean result = MenuUtil.createMenu(getMenu(), token.getAccessToken(),ParamesAPI.payrollPersonalAgentId);
			// 判断菜单创建结果
			if (result)
				log.info("菜单创建成功！");
			else
				log.info("菜单创建失败！");
		}
	}
}
